# Contributor: Łukasz Jendrysik <scadu@yandex.com>
# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=portaudio
pkgver=19.7.0
pkgrel=2
pkgdesc="A cross-platform, open-source C language library for real-time audio input and output"
url="http://www.portaudio.com/"
license="MIT"
arch="all"
makedepends="
	alsa-lib-dev
	autoconf
	automake
	jack-dev
	libtool
	linux-headers
	"
checkdepends="
	alsa-lib
	jack
	"
subpackages="$pkgname-dev libportaudiocxx:_cxx"
source="https://github.com/PortAudio/portaudio/archive/v$pkgver/portaudio-v$pkgver.tar.gz
	portaudio-pkgconfig-alsa.patch
	portaudio-audacity.patch
	"
options="!check" # No unit tests, requires hardware to execute tests

prepare() {
	default_prepare

	update_config_sub
	autoreconf -if

	cd bindings/cpp
	autoreconf -if
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--disable-static \
		--with-jack \
		--with-alsa \
		--enable-cxx
	# race conditions in build cause build failures otherwise
	# https://github.com/PortAudio/portaudio/issues/540
	make -j1
}

check() {
	cd "$builddir"/bin
	local t1
	for t1 in pa_devs pa_fuzz pa_minlat paex_pink paex_read_write_wire paex_record \
		paex_saw paex_sine paex_write_sine paex_write_sine_nonint paqa_devs paqa_errs \
		paqa_latency patest1; do
		msg "$t1":
		./"$t1"
	done

	local t2
	for t2 in buffer callbackstop clip dither hang in_overflow latency leftright \
		longsine many maxsines mono multi_sine out_underflow prime ringmix sine8 \
		sine_channelmaps sine_formats sine_srate sine_time start_stop stop stop_playout \
		toomanysines two_rates underflow wire; do
		msg patest_"$t2":
		./patest_"$t2"
	done
}

package() {
	make -j1 DESTDIR="$pkgdir" install
}

_cxx() {
	pkgdesc="C++ bindings library for portaudio"

	amove usr/lib/libportaudiocpp*
}

sha512sums="
7e347a174109b661a685bcd617cc8fe00929c6fbf28f142fd7709a8ddbb9b5ed6e805be6647a44b4b9441b79e3474561de6f8e351b4ffc024952ed3e0e27ac1c  portaudio-v19.7.0.tar.gz
d58e7f8717f9d451535546e16939a959f63ccdd21bcbbc8e08efde2722382b068603bae6d93449476b206c85160d8084d39b39748b4fb43ab2b6eaee704ba1f8  portaudio-pkgconfig-alsa.patch
b66fb7abe707c3621bbbb05c42df58192a6ff91a563973c196028ac50aa85ad9a803dee3e172d11e1bec34e02d435af653cf38304467637a95384a05210a8bdb  portaudio-audacity.patch
"
